const path = require('path')
// const webpack = require('webpack')
const HTMLWebPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  target: 'web',
  // runtimeCompiler: true,
  devtool: 'inline-source-map',
  devServer: {
    // open: true, // 自动打开浏览器
    // contentBase: './public'
  },
  // 入口
  entry: './src/main.js',
  // 输出
  output: {
    path: resolve('dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: ['vue-loader']
      },
      // {
      //   test: /\.js$/,
      //   exclude: /node_modules/,
      //   use: ['eslint-loader']
      // },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.less$/,
        use: ['style-loader', 'css-loader', 'less-loader']
      },
      {
        test: /\.(gif|jpg|jpeg|png|svg)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              // limit: 1024,
              esModule: false,
              name: 'assets/[name].[ext]'
            }
          }
        ]
      }
    ]
  },
  resolve: {
    alias: {
      vue$: 'vue/dist/vue.esm.js'
    }
  },
  plugins: [
    //
    new HTMLWebPlugin({
      template: './public/index.html',
      title: 'Welcome to Your Vue.js App',
      inject: 'body' // true|body|head|false
      // hash: new Date().getTime(),
    }),
    new VueLoaderPlugin()
  ]
}
